package dao.impl;

import dao.DepartmentDAO;
import tools.JDBCTool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class DepartmentDAOImpl implements DepartmentDAO {

    @Override
    public Map<String, String> getDepartment() {
        Map<String, String> departMap = new HashMap<>();
        try {
            Connection conn = JDBCTool.getConnection();
            String sql = "select * from department";
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                String key = rs.getString("id");
                String value = rs.getString("name");
                departMap.put(key, value);
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return departMap;
    }
}
